package org.easymodelers.template.utils;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import org.easymodelers.template.TemplateProcessingException;

public abstract class TemplateUtils {

	public static String loadTemplate(String path) {
		BufferedReader reader = null;
		try {
			reader = new BufferedReader(new InputStreamReader(TemplateUtils.class.getResourceAsStream(path)));
			StringBuffer content = new StringBuffer();
			String line = null;
			boolean begin = true;
			while ((line=reader.readLine())!=null) {
				if (!begin) {
					content.append("\n");
				} else {
					begin = false;
				}
				content.append(line);
			}
			return content.toString();
		} catch (Exception ex) {
			String message = "Unable to read the template content.";
			throw new TemplateProcessingException(message, ex);
		} finally {
			if (reader!=null) {
				try {
					reader.close();
				} catch(Exception ex) {}
			}
		}
	}
	
}
